Modular invariance and the two-loop vanishing of the cosmological constant