The Infrared Luminosity Function of Galaxies at Redshifts z = 1 and z ~ 2 in the GOODS Fields