A cosmological upper limit on the mass of heavy neutrinos