A 4-2 win over Costa Rica was not enough for Hansi Flick's side, who crash out for the second World Cup campaign in a row.