The evolution of the rest-frame J- and H-band luminosity function of galaxies to z=3.5