def average_detections(detections, predictions, relative_prediction_threshold = 0.25):
  """average_detections(detections, predictions, [relative_prediction_threshold]) -> bounding_box, prediction

  Computes the weighted average of the given detections, where the weights are computed based on the prediction values.

  **Parameters:**

  ``detections`` : [:py:class:`BoundingBox`]
    The overlapping bounding boxes.

  ``predictions`` : [float]
    The predictions for the ``detections``.

  ``relative_prediction_threshold`` : float between 0 and 1
    Limits the bounding boxes to those that have a prediction value higher then ``relative_prediction_threshold * max(predictions)``

  **Returns:**

  ``bounding_box`` : :py:class:`BoundingBox`
    The bounding box which has been merged from the detections

  ``prediction`` : float
    The prediction value of the bounding box, which is a weighted sum of the predictions with minimum overlap
  """
  # remove the predictions that are too low
  prediction_threshold = relative_prediction_threshold * max(predictions)
  detections, predictions = zip(*[[d,p] for d,p in zip(detections, predictions) if p >= prediction_threshold])

  # turn remaining predictions into weights
  s = sum(predictions)
  weights = [p/s for p in predictions]
  # compute weighted average of bounding boxes
  top = sum(w * b.topleft_f[0] for w, b in zip(weights, detections))
  left = sum(w * b.topleft_f[1] for w, b in zip(weights, detections))
  bottom = sum(w * b.bottomright_f[0] for w, b in zip(weights, detections))
  right = sum(w * b.bottomright_f[1] for w, b in zip(weights, detections))

  # compute the average prediction value
  value = sum(w*p for w,p in zip(weights, predictions))

  # return the average bounding box
  return BoundingBox((top, left), (bottom-top, right-left)), value