Fixed compiler error on GCC 4.6.

Added the reference capture for all of the lambda functions (GCC is
more strict with the C++11 standard in this regard).