Photoproduction of π0 mesons off protons and neutrons in the second and third nucleon resonance regions