def modify_intended_for (image_paths, contents, remove=False):
  """
  Modify the given contents dictionary, storing the given image paths under the
  IntendedFor key. If IntendedFor key already exists, its value is replaced by the
  given image paths. If remove flag is True, then the value is replaced by an empty list.
  Returns the sidecar contents dictionary, sorted by keywords.
  """
  contents['IntendedFor'] = [] if remove else image_paths
  sorted_dict = dict(sorted(contents.items()))
  return sorted_dict