MB-9376: Put the reduce function on the heap

Change-Id: Ibe5095c219ca0a17467aa1a96ac58266bc186c5a
Reviewed-on: http://review.couchbase.org/29618
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>