Direct numerical simulation and global stability analysis of three-dimensional instabilities in a lid-driven cavity