Lifetimes of metastable CO and N2 molecules