public int[] getBestHandPoseRanking(int hand) {
      int poseRanking[] = new int[N_POSES];
      int defaultRanking[] = new int[N_POSES];
      for(int iPose = 0; iPose < N_POSES; iPose++) {
          poseRanking[iPose] = iPose;
          defaultRanking[iPose] = iPose;
      }
      int lastBestPose = getBestHandPose(hand);
      if(lastBestPose == -1) return defaultRanking;
      
      float lastBestConfidence = handPoseConfidences[hand][lastBestPose];
      poseRanking[0] = lastBestPose;

      for(int iPose = 1; iPose < N_POSES; iPose++) {
          int nextBestPose = -1;
          float nextBestConfidence = 0;
          for(int i = 0; i < N_POSES; i++) {
              if(handPoseConfidences[hand][i] > nextBestConfidence && handPoseConfidences[hand][i] <= lastBestConfidence && iPose != lastBestPose) {
                  nextBestConfidence = handPoseConfidences[hand][i];
                  nextBestPose = i;
              }
          }
          if(nextBestPose == -1) return defaultRanking;
          poseRanking[iPose] = nextBestPose;
          lastBestPose = nextBestPose;
          lastBestConfidence = nextBestConfidence;
      }

      return poseRanking;
  }