On gauge invariance and minimal coupling