I would try filtering the data then looking for sign changes in the derivative, rather than thresholding it.
B = fir1(8,0.5);
newData = filtfilt(B,1,data);
dt = [0 sign(diff(newData))];
ddt = -[0 diff(dt)];
localMaxima = data(ddt>0);
idx = find(ddt>0);
plot(1:length(data),[data;newData;ddt*max(data)])