Three-dimensional magnetic reconnection and its application to solar flares