def prune_to_peaks(det_obj2_d_raw, det_matrix, num_doppler_bins,
    reserve_neighbor=False):
    """Reduce the CFAR detected output to local peaks.

    Reduce the detected output to local peaks. If reserveNeighbor is toggled, will also return the larger neighbor. For
    example, given an array [2, 1, 5, 3, 2], default method will return [2, 5] while reserve neighbor will return
    [2, 5, 3]. The neighbor has to be a larger neighbor of the two immediate ones and also be part of the peak. the 1st
    element "1" in the example is not returned because it's smaller than both sides so that it is not part of the peak.

    Args:
        det_obj2_d_raw (np.ndarray): The detected objects structured array which contains the range_idx, doppler_idx,
         peakVal and SNR, etc.
        det_matrix (np.ndarray): Output of doppler FFT with virtual antenna dimensions reduced. It has the shape of
            (num_range_bins, num_doppler_bins).
        num_doppler_bins (int): Number of doppler bins.
        reserve_neighbor (boolean): if toggled, will return both peaks and the larger neighbors.

    Returns:
        cfar_det_obj_index_pruned (np.ndarray): Pruned version of cfar_det_obj_index.
        cfar_det_obj_SNR_pruned (np.ndarray): Pruned version of cfar_det_obj_SNR.
    """
    range_idx = det_obj2_d_raw['rangeIdx']
    doppler_idx = det_obj2_d_raw['dopplerIdx']
    next_idx = doppler_idx + 1
    next_idx[doppler_idx == num_doppler_bins - 1] = 0
    prev_idx = doppler_idx - 1
    prev_idx[doppler_idx == 0] = num_doppler_bins - 1
    prev_val = det_matrix[range_idx, prev_idx]
    current_val = det_matrix[range_idx, doppler_idx]
    next_val = det_matrix[range_idx, next_idx]
    if reserve_neighbor:
        next_next_idx = next_idx + 1
        next_next_idx[next_idx == num_doppler_bins - 1] = 0
        prev_prev_idx = prev_idx - 1
        prev_prev_idx[prev_idx == 0] = num_doppler_bins - 1
        prev_prev_val = det_matrix[range_idx, prev_prev_idx]
        next_next_val = det_matrix[range_idx, next_next_idx]
        is_neighbor_of_peak_next = (current_val > next_next_val) & (current_val
             > prev_val)
        is_neighbor_of_peak_prev = (current_val > prev_prev_val) & (current_val
             > next_val)
        pruned_idx = (current_val > prev_val) & (current_val > next_val
            ) | is_neighbor_of_peak_next | is_neighbor_of_peak_prev
    else:
        pruned_idx = (current_val > prev_val) & (current_val > next_val)
    det_obj2_d_pruned = det_obj2_d_raw[pruned_idx]
    return det_obj2_d_pruned
