That's funny. Did you just copy and paste code from OpenMVS RefineMesh module for your mesh refinement?
Even if user decimate mesh to a deep **it and will play with 50images, such heado-on solution will always have not enough memory. At least OpenMVS can use CPU and RAM. And 300+ images still possible to process on 64Gb RAM.
2017-09-20 16:28:32 RefineMesh: quality = Ultra high, iterations = 20, smoothness = 1
2017-09-20 16:28:32 Using device: GeForce GTX 960, 8 compute units, 2048 MB global memory, compute capability 5.2
2017-09-20 16:28:32 max work group size 1024
2017-09-20 16:28:32 max work item sizes [1024, 1024, 64]
2017-09-20 16:28:32 Analyzing mesh detalization...
2017-09-20 16:29:05 Memory required: 1743 Mb + 6 Mb = 1749 Mb
2017-09-20 16:29:05 Stage #1 out of 4
2017-09-20 16:29:05 Subdividing mesh...
2017-09-20 16:29:07 Memory required: 27 Mb + 6 Mb = 33 Mb
2017-09-20 16:29:07 Loading photos...
2017-09-20 16:29:09 loaded photos in 2.642 seconds
2017-09-20 16:29:09 Refining model...
2017-09-20 16:29:12 Iteration #1 out of 20
2017-09-20 16:29:40 Iteration #2 out of 20
2017-09-20 16:29:59 Iteration #3 out of 20
2017-09-20 16:30:07 Iteration #4 out of 20
2017-09-20 16:30:16 Iteration #5 out of 20
2017-09-20 16:30:28 Iteration #6 out of 20
2017-09-20 16:30:49 Iteration #7 out of 20
2017-09-20 16:31:12 Iteration #8 out of 20
2017-09-20 16:31:34 Iteration #9 out of 20
2017-09-20 16:31:54 Iteration #10 out of 20
2017-09-20 16:32:16 Iteration #11 out of 20
2017-09-20 16:32:38 Iteration #12 out of 20
2017-09-20 16:32:56 Iteration #13 out of 20
2017-09-20 16:33:14 Iteration #14 out of 20
2017-09-20 16:33:38 Iteration #15 out of 20
2017-09-20 16:33:57 Iteration #16 out of 20
2017-09-20 16:34:20 Iteration #17 out of 20
2017-09-20 16:34:39 Iteration #18 out of 20
2017-09-20 16:35:00 Iteration #19 out of 20
2017-09-20 16:35:09 Iteration #20 out of 20
2017-09-20 16:35:17 Stage #2 out of 4
2017-09-20 16:35:17 Subdividing mesh...
2017-09-20 16:35:20 Memory required: 108 Mb + 19 Mb = 128 Mb
2017-09-20 16:35:20 Loading photos...
2017-09-20 16:35:23 loaded photos in 2.516 seconds
2017-09-20 16:35:23 Refining model...
2017-09-20 16:35:31 Iteration #1 out of 20
2017-09-20 16:35:58 Iteration #2 out of 20
2017-09-20 16:36:25 Iteration #3 out of 20
2017-09-20 16:37:01 Iteration #4 out of 20
2017-09-20 16:37:42 Iteration #5 out of 20
2017-09-20 16:38:09 Iteration #6 out of 20
2017-09-20 16:38:37 Iteration #7 out of 20
2017-09-20 16:39:05 Iteration #8 out of 20
2017-09-20 16:39:32 Iteration #9 out of 20
2017-09-20 16:39:59 Iteration #10 out of 20
2017-09-20 16:40:26 Iteration #11 out of 20
2017-09-20 16:41:02 Iteration #12 out of 20
2017-09-20 16:41:34 Iteration #13 out of 20
2017-09-20 16:42:08 Iteration #14 out of 20
2017-09-20 16:42:42 Iteration #15 out of 20
2017-09-20 16:43:15 Iteration #16 out of 20
2017-09-20 16:44:33 Iteration #17 out of 20
2017-09-20 16:46:20 Iteration #18 out of 20
2017-09-20 16:46:52 Iteration #19 out of 20
2017-09-20 16:47:25 Iteration #20 out of 20
2017-09-20 16:47:56 Stage #3 out of 4
2017-09-20 16:47:56 Subdividing mesh...
2017-09-20 16:48:07 Memory required: 435 Mb + 72 Mb = 508 Mb
2017-09-20 16:48:07 Loading photos...
2017-09-20 16:48:10 loaded photos in 2.516 seconds
2017-09-20 16:48:10 Refining model...
2017-09-20 16:48:42 Iteration #1 out of 20
2017-09-20 16:50:57 Iteration #2 out of 20
2017-09-20 16:52:44 Iteration #3 out of 20
2017-09-20 17:05:25 Iteration #4 out of 20
2017-09-20 17:07:18 Iteration #5 out of 20
2017-09-20 17:08:58 Iteration #6 out of 20
2017-09-20 17:10:39 Iteration #7 out of 20
2017-09-20 17:12:18 Iteration #8 out of 20
2017-09-20 17:13:58 Iteration #9 out of 20
2017-09-20 17:15:39 Iteration #10 out of 20
2017-09-20 17:17:19 Iteration #11 out of 20
2017-09-20 17:18:59 Iteration #12 out of 20
2017-09-20 17:20:38 Iteration #13 out of 20
2017-09-20 17:22:18 Iteration #14 out of 20
2017-09-20 17:23:57 Iteration #15 out of 20
2017-09-20 17:25:38 Iteration #16 out of 20
2017-09-20 17:27:17 Iteration #17 out of 20
2017-09-20 17:28:57 Iteration #18 out of 20
2017-09-20 17:30:38 Iteration #19 out of 20
2017-09-20 17:32:17 Iteration #20 out of 20
2017-09-20 17:33:57 Stage #4 out of 4
2017-09-20 17:33:57 Subdividing mesh...
2017-09-20 17:34:42 Memory required: 1743 Mb + 287 Mb = 2030 Mb
2017-09-20 17:34:42 Loading photos...
2017-09-20 17:34:45 loaded photos in 3.218 seconds
2017-09-20 17:34:45 Refining model...
2017-09-20 17:36:57 Iteration #1 out of 20
2017-09-20 17:36:58 Finished processing in 4106.3 sec (exit code 0)
2017-09-20 17:36:58 Error: out of memory (2) at line 179