Stability and electronic properties of carbon nanotubes doped with transition metal impurities