Euclid preparation-IV. Impact of undetected galaxies on weak-lensing shear measurements