Allocate TPL buffers based on lag_in_frames

Memory usage has been optimized by allocating
TPL buffers (stats buffers and frame buffers)
based on lag_in_frames as discussed in the following
bug.

BUG=aommedia:2873

This CL is bit-exact with no impact on encode-time.

Resolution    Tile    Avg Memory reduction
                      Single   Multi
                      thread   thread
640x360       2x1     8.54%    8.03% (2 threads)
832x480       2x1     9.68%    9.26% (2 threads)
1280x720      2x2     10.78%   10.07% (4 threads)
1920x1080     4x2     11.59%   10.71% (8 threads)

Change-Id: Ide91ba8980ccc513345623b859c9a6f0795da0cf
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index e33ab31..1532b82 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -157,9 +157,7 @@
   // stats buffers are not allocated.
   if (lag_in_frames <= 1) return;
 
-  // TODO(aomedia:2873): Explore the allocation of tpl buffers based on
-  // lag_in_frames.
-  for (int frame = 0; frame < MAX_LAG_BUFFERS; ++frame) {
+  for (int frame = 0; frame < lag_in_frames; ++frame) {
     AOM_CHECK_MEM_ERROR(
         &ppi->error, tpl_data->tpl_stats_pool[frame],
         aom_calloc(tpl_data->tpl_stats_buffer[frame].width *