You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: calculate_overlap.m
    path of file: ./repos/toolkit-legacy/sequence
    
    the code of the file until where you have to start completion: function [overlap, only1, only2] = calculate_overlap(T1, T2, bounds)
% calculate_overlap  Calculates overlap for two trajectories

    
function [overlap, only1, only2] = calculate_overlap(T1, T2, bounds)
% calculate_overlap  Calculates overlap for two trajectories
%
% The function calculates per-frame overlap between two trajectories. Besides the
% region overlap the function also returns cointainment of the second trajectory in the
% first and containment of the first trajectory in the second.
%
% If the trajectories are not of equal length, then the overlaps are calculated up
% to the end