Stability of Bose-Einstein condensates in two-dimensional optical lattices