Quark masses from lattice QCD at the next-to-leading order