Near-infrared CO emission in young stellar objects