Update the forward_stack_ priority list

Follow the naming convention related to the ARF and intermediate
ARFs.

BUG=b/241257063

Change-Id: Ic3d7524feb8284fa946b5141474659efc9b15286
diff --git a/av1/reference_manager.cc b/av1/reference_manager.cc
index 08b124c..456cec9 100644
--- a/av1/reference_manager.cc
+++ b/av1/reference_manager.cc
@@ -81,7 +81,10 @@
   if (ref_update_type == RefUpdateType::kForward) {
     int size = static_cast<int>(forward_stack_.size());
     if (priority_idx < size) {
-      return forward_stack_[size - priority_idx - 1];
+      if (priority_idx == 0)
+        return forward_stack_[priority_idx];
+      else
+        return forward_stack_[size - priority_idx];
     }
   } else if (ref_update_type == RefUpdateType::kBackward) {
     int size = static_cast<int>(backward_queue_.size());
diff --git a/test/ratectrl_qmode_test.cc b/test/ratectrl_qmode_test.cc
index 6855e0f..9b2963c 100644
--- a/test/ratectrl_qmode_test.cc
+++ b/test/ratectrl_qmode_test.cc
@@ -695,11 +695,12 @@
   int ref_count = ref_manager.GetRefFrameCountByType(type);
   int prev_global_order_idx = ref_manager.CurGlobalOrderIdx();
   // The lower the priority is, the closer the gop_frame.global_order_idx should
-  // be with cur_global_order_idx_
+  // be with cur_global_order_idx_, with exception of a base layer ARF.
   for (int priority = 0; priority < ref_count; ++priority) {
     GopFrame gop_frame = ref_manager.GetRefFrameByPriority(type, priority);
     EXPECT_EQ(gop_frame.is_valid, true);
     if (type == RefUpdateType::kForward) {
+      if (priority == 0) continue;
       EXPECT_GE(gop_frame.global_order_idx, prev_global_order_idx);
     } else {
       EXPECT_LE(gop_frame.global_order_idx, prev_global_order_idx);
@@ -772,7 +773,7 @@
   std::vector<ReferenceFrame> ref_frame_list =
       ref_manager.GetRefFrameListByPriority();
   EXPECT_EQ(ref_frame_list.size(), order_idx_list.size());
-  std::vector<int> expected_global_order_idx = { 2, 0, 1, 4 };
+  std::vector<int> expected_global_order_idx = { 4, 0, 1, 2 };
   std::vector<ReferenceName> expected_names = { ReferenceName::kAltrefFrame,
                                                 ReferenceName::kGoldenFrame,
                                                 ReferenceName::kLastFrame,